<script type="text/javascript">
var $datatable_product;
var $datatable_export_bill;
    
$(document).ready(function() {
    $datatable_product = $('#datatable_product');
    $datatable_export_bill = $('#datatable_export_bill');
    //$datatable_construction = $('#datatable_construction');
    
    oTable_exportBill = $datatable_export_bill.dataTable({
        "bJQueryUI": true,
        "bInfo": false,
        "bPaginate": false,
        "bFilter" : false,
        "bLengthChange": false,
        "bInfo": false,
        "aoColumns": [
          { "sClass": "","bSortable": false},
          { "sClass": "","bSortable": false},
          { "sClass": "","bSortable": false },
          { "sClass": "","bSortable": false },
          { "sClass": "","bSortable": false },
          { "sClass": "","bSortable": false },
          { "sClass": "","bSortable": false },
          { "sClass": "","bSortable": false },
        ],
        "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
            $(nRow).attr("stt",iDisplayIndex);
            $(nRow).attr("modify",'edit');
            $('td:eq(0)', nRow).html( iDisplayIndex+1 );
            return nRow;
        }        
    });
    
    oTable_product = $datatable_product.dataTable({
        "bJQueryUI": true,
        "bInfo": false,
        "bPaginate": false,
        "bFilter" : false,
        "bLengthChange": false,
        "bInfo": false,
        "aoColumns": [
          { "sClass": "","bSortable": false},
          { "sClass": "","bSortable": false},
          { "sClass": "","bSortable": false },
          { "sClass": "","bSortable": false },
          { "sClass": "","bSortable": false },
          { "sClass": "","bSortable": false }
        ],
        "fnRowCallback": function( nRow, aData, iDisplayIndex ) {
            $(nRow).attr("stt",iDisplayIndex);
            $(nRow).attr("modify",'edit');
            $('td:eq(0)', nRow).html( iDisplayIndex+1 );
            return nRow;
        }        
    });
    
    $(function() {
        $( "#tabs" ).tabs();
    });

} );

function finishconstruction(){
    $('#frm_end_construction').submit();
}
</script>

<div class="warpp">
    
    <div>
        <table>
            <tbody>
                <tr>
                    <td><label><?php print lang('vt_constructionname'); ?>:</label></td>
                    <td><?php print $construction->name; ?></td>
                </tr>
                <tr>
                    <td><label><?php print lang('vt_createddate'); ?>:</label></td>
                    <td><?php print $construction->created_date; ?></td>
                </tr>
                <tr>
                    <td><label><?php print lang('vt_enddate'); ?>:</label></td>
                    <td><?php print ($construction->end_date == null )? 'N/A':$construction->end_date; ?></td>
                </tr>
                <tr>
                    <td><label><?php print lang('vt_trangthai'); ?>:</label></td>
                    <td>
                    <?php 
                        if($construction->status == -1){
                            print lang('vt_tt_delete');
                        }elseif($construction->status == 0){
                            print 'N/A';
                        }elseif($construction->status == 1){
                            print lang('vt_tt_dangthicong');
                        }elseif($construction->status == 2){
                            print lang('vt_tt_ketthuc');
                        }
                    ?></td>
                </tr>
            </tbody>
        </table>
    </div>

    <div class="menu-button">
        <div class="message"></div>
        <?php if($construction->status == 1): ?>
        <button onclick="finishconstruction();"><?php print lang('vt_finishconstruction'); ?></button>
        <form id="frm_end_construction" style="display: none;" action="<?php print site_url('vt/end_construction') ?>" method="post">
            <input type="hidden" name="id" value="<?php print $construction->id; ?>">
        </form>
        <?php endif; ?>
        <div class="clear"></div>
    </div>
    
    <div id="tabs">
        <ul>
            <li><a href="#tabs-1"><?php print lang('vt_tab_billexport'); ?></a></li>
            <li><a href="#tabs-2"><?php print lang('vt_tab_productexport'); ?></a></li>
        </ul>
        <div id="tabs-1">
            <?php if($export_data != null): ?>
            <div>
                <table cellpadding="0" cellspacing="0" border="0" class="display dataTable" id="datatable_export_bill" active_url="">
                    <thead>
                        <tr>
                            <th class="ui-state-default"><?php print lang('vt_stt'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_billcode'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_nguoinhap'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_nguoinhanphieu'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_total-vat'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_vat%'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_vattotal'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_total+vat'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $k = 1; $count_totalex = 0; $count_totalvatex = 0; ?>
                        <?php foreach($export_data As $exp): ?>
                        <tr class="<?php print ( $k%2 == 0 ) ? 'even':'odd'; ?>">
                            <td><?php print $k; ?></td>
                            <td><a href="<?php print site_url('xk/bill/'.$exp->id); ?>"><?php print $exp->bill_code; ?></a></td>
                            <td><?php print $exp->username; ?></td>
                            <td><?php print $exp->name; ?></td>
                            <td><?php print decimal_format($exp->bill_total); ?></td>
                            <td><?php print decimal_format($exp->bill_vat); ?></td>
                            <td><?php print decimal_format($exp->bill_vatprice); ?></td>
                            <td><?php print decimal_format($exp->bill_totalvat); ?></td>
                        </tr>
                        <?php 
                            $k++;
                            $count_totalex += $exp->bill_total;
                            $count_totalvatex += $exp->bill_totalvat;
                        ?>
                        <?php endforeach; ?>
                    </tbody>
                    <tfoot>
                        <tr>
                            <th colspan="4" align="right" class="ui-state-default">Tong Tien(-VAT):</th>
                            <th class="ui-state-default"><?php print decimal_format($count_totalex); ?></th>
                            <th colspan="2" align="right" class="ui-state-default">Tong Tien(+VAT):</th>
                            <th class="ui-state-default"><?php print decimal_format($count_totalvatex); ?></th>
                        </tr>
                    </tfoot>
                </table>
            </div>
            <?php endif; ?>    
        </div>
        <div id="tabs-2">
            <?php if( isset($products) ): ?>
            <div>
                <table cellpadding="0" cellspacing="0" border="0" class="display dataTable" id="datatable_product" active_url="">
                    <thead>
                        <tr>
                            <th class="ui-state-default"><?php print lang('vt_stt'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_mavt'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_tenvt'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_donvitinh'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_slxuat'); ?></th>
                            <th class="ui-state-default"><?php print lang('vt_sltra'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $i = 1; ?>
                        <?php foreach($products As $row): ?>
                        <tr class="<?php print ( $i%2 == 0 ) ? 'even':'odd'; ?>">
                            <td><?php print $i; ?></td>
                            <td><?php print $row['code']; ?></td>
                            <td><?php print $row['name']; ?></td>
                            <td><?php print $row['dvt']; ?></td>
                            <td><?php print decimal_format($row['export']); ?></td>
                            <td><?php print decimal_format($row['revert']); ?></td>
                        </tr>
                        <?php $i++; ?>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
            <?php endif; ?>
        </div>
    </div>    
</div>